<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>职位管理</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/easyui/themes/metro-admin/easyui.css">
</head>
<body>
<style type="text/css">

</style>

<div style="width:90%;height:100%;background:white;padding:20px;margin:20px auto;">
	<a id="position-add" href="#" class="easyui-linkbutton" data-options="width:80,height:25">新增</a>
	<table class="easyui-datagrid" id="dg" data-options="width:990,height:400"></table>
</div>

<script type="text/javascript">
$('#dg').datagrid({
    url:'select-pdr',
    singleSelect:true,
    columns:[[
		{field:'position_name',title:'职位名称',width:165,align:'center'},
		{field:'depart_name',title:'所属部门',width:275,align:'center'},
		{field:'rank_id',title:'职级',width:275,align:'center'},
		{field:'cc',title:'操作',width:275,fixed:false,align:'center',
			formatter:function(value,row,index){
				return "<input type='button' class='role-button' a='"+row.rank_id+"' b='"+row.position_id+"' c='"+row.Depart_id+"' value='删除' onClick='bianji(this)'/>";
			}
		}
    ]]
});

//删除
function bianji(t){
	var a=$(t).attr("a");
	var b=$(t).attr("b");
	var c=$(t).attr("c");
	$.ajax({
		url:"delete-pdr",
		type:"post",
		data:{"postion_id":b,"Depart_id":c,"rank_id":a},
		success:function(data){
			if(data==2){
				alert("删除成功");
			$('#dg').datagrid('reload');
			}else if(data==1){
				alert("删除失败，该部门职位存在人员");
			}
		}
	});
}



$(function(){
	$("#position-add").click(function(){
		$("#zhezhao").show();
	});
	//点击关闭按钮
	   $(".guanbiya").click(function(){
		   $("#zhezhao").hide();
	   });
	   $("#position-off").click(function(){
		   $("#zhezhao").hide();
	   });
	   $("#depart-name").click(function(){
			$(".depart_list").show();
		});
		$(".depart_list").tree({
		    url:'init-depart',
		    	onClick: function(node){
		    		    $(".depart_list").hide();
			    		$("#depart-name").val(node.text);
			    		$("#depart-name").attr({"abbr":node.id}); 
		    		
		    	} 
		    	
		});
		
		$('.position-name').combogrid({
		    idField:'position_id',
		    textField:'position_name',
		    url:'ps',
		    columns:[[
		    {field:'position_name',title:'请选择',width:170}
		    ]],
		    onSelect: function(rowIndex, rowData){
		    	$('.position-name').attr({"abbr":rowData.position_id});
		    }
		    });
		
		$('#rank_id').combogrid({
		    idField:'rank_id',
		    textField:'rank_id',
		    url:'select-rank',
		    columns:[[
		    {field:'rank_id',title:'请选择',width:170}
		    ]]
		    });
		
		$("#position-on").click(function(){
			var position=$(".position-name").attr("abbr");
			var depart=$("#depart-name").attr("abbr");
			var rank=$("#rank_id").val();
			console.log(depart);
			$.ajax({
				url:"add-pdr",
				type:"post",
				data:{"postion_id":position,"Depart_id":depart,"rank_id":rank},
				success:function(data){
					 $("#zhezhao").hide();
					$('#dg').datagrid('reload');
					$("#content-admin").panel('open').panel('refresh','hr-position');
				}
			});
		});
	
})
</script>


<!-- 遮罩层1+新增+编辑 -->
<div id="zhezhao" style="width:100%;height:100%;position:fixed; top:0px;
background: rgba(0, 0, 0, 0.5);text-align:center;left:0;z-index:10;display:none;" >

<div class="kuangchuang" style="margin:150px auto;width:500px;height:200px;background:white;border-radius:3px;">
	<div style="width:100%;height:30px;">
		<span style="width:50px;height:30px;line-height:30px;display:inline-block;float:left;margin-left:20px;" class="xinzeng_text"></span>
		<button class="icon-close guanbiya" style="float:right;width:30px;height:30px;cursor:pointer;border:none;outline:none;"></button>
	</div>
	<div style="width:100%;height:135px;border-top:solid 1px #E5E5E5;border-bottom:solid 1px #E5E5E5;">
		<p>
			<span style="display:inline-block;">职位名称：</span><input class="easyui-combogrid position-name" style="width:170px;"/>
		</p>
		<p>
			<span>部门名称：</span><input type="text" id="depart-name" style="position:relative;"/>
			<ul class="depart_list" style="overflow:auto;display:none;width:190px;height:200px;background:white;margin-left:40%;padding:10px 10px;box-shadow: 2px 4px 6px 1px grey;
   			 border-radius: 2px;position:absolute;left:90px;top:260px;z-index:1;"></ul>
		</p>
		<p>
			<span style="width:80px;display:inline-block;">职级：</span><input type="text" class="easyui-combogrid" id="rank_id" style="width:170px;"/>
		</p>
	</div>
	<div style="width:100%;height:30px;">
		<div style="width:140px;float:right;margin-top:5px;">
			<a id="position-off" href="#" class="easyui-linkbutton" data-options="width:60,height:25">关闭</a>
			<a id="position-on" href="#" class="easyui-linkbutton" data-options="width:60,height:25">确定</a>
		</div>
	</div>
</div>

</div>
</body>
</html>